#ifndef __DTM_437_H
#define __DTM_437_H

#include <stdint.h>
#include "J1939_Config.h"
#include "J1939.h"
#include "can_driver.h"

#define DTM437_WR 0x01
#define DTM437_RD 0x00

#define DTM437_DeviceStatus 0x2080
#define DTM437_TagData      0xA001

typedef enum{
    DTM_OK = 0,
    DTM_VALUE_TOO_SMALL,
    DTM_VALUE_TOO_BIG,
    DTM_PARAM_NOT_EXIST,
    DTM_PARAM_CANT_WRITE,
    DTM_PARAM_CANT_READ,
    DTM_PARAM_NO_ACCESS,
    DTM_INVALID_DATA_SIZE,
    DTM_PARAM_WRITE_BLOCKED,
    DTM_INVALID_CMD,
    DTM_UNKOWN_ERR,
    DTM_ERR_WR_RD_TAG
}DTM437_StatusCode_T;

#pragma pack(push)
#pragma pack(1)

typedef union{
    struct
    {
        uint16_t param;
        uint8_t  wr_rd;
        uint8_t status;
        uint8_t data[4];
    }s_;
    uint8_t buf[8];
}DTM437_Frame_T;

#pragma pack(pop)

class DTM437{
public:
    J1939_MESSAGE frame;

private:
    boost::shared_ptr<boost::thread> poll_thread;

public:
    DTM437();
    bool init(void);
    void ms10_loop(void);
    void async_access_param(uint16_t param, uint8_t wr_rd, const uint8_t* data);
    void async_get_rfid_data(uint16_t tag_addr, uint16_t len);
    void async_get_status(void);
    void async_set_rfid_data(uint16_t tag_addr, uint8_t* data, uint16_t len);
    void stop(void);
    
private:
    bool can_driver_init(void);

};

#endif
